import 'dart:convert';

import 'package:mvvm_provider/generated/json/base/json_field.dart';
import 'package:mvvm_provider/generated/json/cartoon_model.g.dart';

@JsonSerializable()
class CarDataModel {
  List<CartoonModel>? feeds;
  int? show_times;
  CarDataModel();

  factory CarDataModel.fromJson(Map<String, dynamic> json) => $CarDataModelFromJson(json);

  Map<String, dynamic> toJson() => $CarDataModelToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }
}

@JsonSerializable()
class CartoonModel {
  @JSONField(name: "item_id")
  String? itemId;
  @JSONField(name: "parent_id")
  String? parentId;
  String? title;
  @JSONField(name: "jump_value")
  String? jumpValue;
  int? type;
  String? image;
  int crossAxisCount = 1;
  int mainAxisCount = 1;
  @JSONField(name: "comic_info")
  CommicInfoModel? comicInfo;
  @JSONField(name: "create_time")
  String? createTime;

  /// 是否收藏
  bool? isCollection;
  CartoonModel();

  factory CartoonModel.fromJson(Map<String, dynamic> json) => $CartoonModelFromJson(json);

  Map<String, dynamic> toJson() => $CartoonModelToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }
}

@JsonSerializable()
class CommicInfoModel {
  String? decision;
  String? lastest_short_title;
  String? title;
  int? is_finish;
  String? main_style_name;
  double? score;
  List<String>? styles;
  List<String>? tags;
  CommicInfoModel();

  String get tagsName {
    if ((tags ?? []).isEmpty) return "暂无分类";
    String result = '';
    for (int i = 0; i < tags!.length; i++) {
      result += '${tags![i]}，';
    }
    return result.substring(0, result.length - 1);
  }

  factory CommicInfoModel.fromJson(Map<String, dynamic> json) => $CommicInfoModelFromJson(json);

  Map<String, dynamic> toJson() => $CommicInfoModelToJson(this);

  @override
  String toString() {
    return jsonEncode(this);
  }
}
